package JUC.第05章_中断机制_LockSupport;//自己自行停止，

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;


public class A2_Atomic实现中断 {
    static AtomicBoolean ab = new AtomicBoolean(false);
    public static void main(String[] args) {
        Atomic实现中断();
    }
    private static void Atomic实现中断() {
        new Thread(()->{
            while (true){
                if(ab.get()){
                    System.out.println("AtomicBoolean : Stop");
                    break;
                }
                System.out.println("AtomicBoolean : hello");
                try {TimeUnit.MILLISECONDS.sleep(5);} catch (InterruptedException e) {e.printStackTrace();}
            }
        }).start();

        try {TimeUnit.MILLISECONDS.sleep(20);} catch (InterruptedException e) {e.printStackTrace();}
        //间隔时间

        new Thread(()->{ab.set(true);}).start();
    }

}
